<div id="left_nav" class="span3" style="padding: 0px;">
    <div id="nav_group" class="inner_shadow">
        <?php
        echo $this->element('bank/nav_branch_sup');
        ?>
    </div>
</div>

<div class="span8" style="padding:10px; background-color: #fff; min-height: 480px;">
    <h4>Transactions Trails</h4>
    <br />

    <h4>Filter</h4>
    <?php echo $this->Form->create('Query', array('id' => 'form-query', 'class' => 'form form-horizontal', 'inputDefaults' => array('label' => false,'div' => false)));?>
    <table class="table ">
        <tr><td>Reference</td><td>Start Date</td><td>End Date</td><td>Branch</td><td>Teller</td></tr>
        <tr>
            <td>
                <?php echo $this->Form->input('trans_ref_no', array('id'=>'trans_ref_no','placeholder' => 'CRA00000000','class' => 'input-medium','div' => false, 'label' => false));?>
            </td>
            <td>
                <?php echo $this->Form->input('start_dt', array('id'=>'start_dt','placeholder' => 'yyyy-mm-dd', 'default'=>$default_start_dt,'class' => 'input-small','div' => false, 'label' => false));?>
            </td>
            <td>
                <?php echo $this->Form->input('end_dt', array('id'=>'end_dt','placeholder' => 'yyyy-mm-dd', 'default'=>$default_end_dt,'class' => 'input-small','div' => false, 'label' => false));?>
            </td>
            <td>
                <?php echo $this->Form->input('branch', array('id'=>'branch', 'options'=>$branch_list, 'default'=>$branch_id, 'class' => 'input-medium','div' => false, 'label' => false));?>
            </td>
            <td>
                <?php echo $this->Form->input('teller', array('id'=>'teller', 'options'=>array(), 'class' => 'input-medium','div' => false, 'label' => false));?>
            </td>
        </tr>
        <tr>
            <td colspan="5">
                <div class="controls">
                    <button type="submit" id="re_query-btn" class="btn btn-primary">Query</button>
                    <button type="button"  id="print-btn" class="btn">Print</button>
                    <button type="button"  id="export-btn" class="btn">Export</button>
                </div>
            </td>
        </tr>
    </table>
    <?php echo $this->Form->end();?>

    <table id="flex">
        <!-- <thead>
             <tr><th>Student Name</th><th>Index Number</th><th>Fee Type</th><th>Fee Amount</th><th>Paid</th><th>Balance</th></tr>
         </thead>-->
        <tbody>
        <?php
        $tl_credit = 0;
        $tl_debit = 0;
        foreach ($data_table as $obj) {
            $trans = $obj['Transaction'];
            $trans_id = $trans['id'];
            $teller_d = $obj['BankUser'];
            $branch_d = $obj['BankBranch'];
            $trans_details = $obj['TransactionBankDetail'];
            $payment_method = $trans_details['payment_method'];
            $trans_item = $obj['TransactionItem'];

            $credit= $auth_amt = doubleval($trans_item['credit_amt']) ;
            $debit = doubleval($trans_item['debit_amt']);

            $tl_credit = $tl_credit + $credit;
            $tl_debit = $tl_debit + $debit;
            ?>
            <tr data-trans-id="<?php echo $trans_id; ?>" data-amount="<?php echo $auth_amt; ?>"  data-payment_method="<?php echo $payment_method; ?>">
                <td><?php echo $this->App->covertDate($trans['created'],'uis');?></td>
                <td><?php echo $trans['trans_ref_no']; ?></td>
                <td><?php echo $branch_d['branch_name'];?></td>
                <td><?php echo $teller_d['fname'].' '.$teller_d['mname'].' '.$teller_d['lname'] ;?></td>
                <td><?php echo $controller->formatNumber($credit,'money');?></td>
                <td> <a href="javascript:void(0);" class="btn btn-mini btn-danger revert_btn"><i class="icon icon-undo"></i> Revert</a></td>
            </tr>
            <?php
            //}
        }
        if($tl_credit > 0){
            ?>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td><strong>Totals</strong></td>
                <td><strong><?php echo $controller->formatNumber($tl_credit,'money');?></strong></td>
               <!-- <td><strong><?php /*echo $controller->formatNumber($tl_debit,'money');*/?></strong></td>-->
            </tr>
        <?php
        }
        ?>
        </tbody>
    </table>

    <form id="print-export-form" method="post" action="<?php echo $this->Html->url(array('controller' => 'Bank', 'action' => 'print_export_transactions')); ?>" target="PrintExportWindow">
        <input type="hidden" name="data_type" id="data_type" value="" />
        <input type="hidden" name="data_trans_ref_no" id="data_trans_ref_no"  value="" />
        <input type="hidden" name="data_start_dt" id="data_start_dt"  value="" />
        <input type="hidden" name="data_end_dt" id="data_end_dt"  value="" />
        <input type="hidden" name="data_branch" id="data_branch"  value="" />
        <input type="hidden" name="data_teller" id="data_teller"  value="" />
    </form>


    <div class="modals">

        <div id="trans_reversal_modal" class="modal hide fade">
            <form class="form form-horizontal" method="post" action="<?php echo $this->Html->url(array('controller' => 'Bank','action' => 'credit_reversal')); ?>" enctype="" style="margin: 0px;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4>Revert Credit Transaction</h4>
                </div>
                <div class="modal-body">

                    <p>
                        You are about to revert the selected <span class="info" id="pay_method"></span> transaction,
                        debit the student account by GHC <span class="info" id="amount"></span>.
                    </p>

                    <p>If you will like to proceed, please specify the reason for the reversal below: <br /><br /></p>

                    <div class="control-group">
                        <label class="control-label" for="address">Revert Reason:</label>
                        <div class="controls">
                            <textarea name="Transaction[revert_reason]" id="revert_reason" class="input" required=""></textarea>
                        </div>
                    </div>

                    <input type="hidden" name="Transaction[id]" id="transaction_id" value="" />
                    <input type="hidden" name="Transaction[student_user_id]" id="student_id" value="" />
                    <input type="hidden" name="Transaction[debit_amt]" id="transaction_debit_amt" value="" />

                </div>
                <div class="modal-footer">
                    <button type="submit" href="<?php echo $this->Html->url(array('action' => 'credit_reversal')); ?>" id="revert_btn" class="btn btn-danger">Revert</button>
                    <a href="#trans_reversal_modal" class="btn" data-toggle="modal">Close</a>
                </div>
            </form>
        </div>

        <div id="message_modal" class="modal hide fade">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4>Message Title</h4>
            </div>
            <div class="modal-body">
                Message Body
            </div>
            <div class="modal-footer">
                <a href="#" class="btn" data-dismiss="modal" id="message_modal_close_callback">Close</a>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var branch_tellers = <?php echo json_encode($branch_tellers); ?>;
    var selected_teller = <?php echo json_encode($teller); ?>;
</script>
<?php
    echo $this->Html->script('bank/transactions.js');
?>